package GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import Joc.Joc;
import Joc.JocStates;
import Model.EroareCanaMessagesLitere;
import Model.HandlerMessagesCana;

public class IntroducereDateCana {
	JFrame frame;
	JPanel panelCani;
	JTextField cana1;
	JTextField cana2;
	JLabel label;
	JButton buttonSave;
	JButton buttonCancel;
	public static ArrayList<String> date;
	
	public IntroducereDateCana(){
		frame = new JFrame("Introducere Date Cani");
		panelCani = new JPanel();
		panelCani.setLayout(null);

		ImageIcon newIcon = new ImageIcon("cana.png");
		label = new JLabel();
		label.setIcon(newIcon);
		label.setBounds(5, 0, 302, 204);
		panelCani.add(label);
		
		label=new JLabel("Cana 1 :");
		label.setBounds(5, 210, 90, 25);
		panelCani.add(label);
		
		cana1=new JTextField("3");
		cana1.setBounds(55, 210, 70, 25);
		cana1.setEditable(true);
		panelCani.add(cana1);
		
		label=new JLabel("Litri");
		label.setBounds(130, 210, 30, 25);
		panelCani.add(label);
		
		label=new JLabel("Cana 2 :");
		label.setBounds(170, 210, 90, 25);
		panelCani.add(label);
		
		cana2=new JTextField("4");
		cana2.setBounds(220, 210, 70, 25);
		cana2.setEditable(true);
		panelCani.add(cana2);
		
		label=new JLabel("Litri");
		label.setBounds(290, 210, 30, 25);
		panelCani.add(label);
		
		buttonSave = new JButton("Save");
		buttonSave.setBounds(110, 260, 70, 25);
		buttonSave.addActionListener(new Action());
		panelCani.add(buttonSave);

		buttonCancel = new JButton("Cancel");
		buttonCancel.setBounds(200, 260, 80, 25);
		buttonCancel.addActionListener(new Action());
		panelCani.add(buttonCancel);
		
		frame.add(panelCani);
		frame.setSize(350, 350);
		frame.setVisible(true);
		frame.setResizable(false);

	}

	
	public ArrayList<String> getDataFromTextField() {
		// TODO Auto-generated method stub
		ArrayList<String> list=new ArrayList<String>();
		String c1 = cana1.getText();
		String c2= cana2.getText();
		list.add(c1);
		list.add(c2);
		return list;
	}
	
	class Action implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {
			if (e.getSource() == buttonCancel){
				frame.dispose();
				MassagePanel.clearMessagesPanel();
				MassagePanel.writeMessagePanel("Start the Game!");
			}
			else if (e.getSource() == buttonSave) {
			HandlerMessagesCana handMessaCana = new EroareCanaMessagesLitere();
			if (handMessaCana.HandleRequest(getDataFromTextField())==false){
					MassagePanel.writeMessagePanel("[INFO] Datele pentru Cani s-au introdus corect");
					date = getDataFromTextField();
					Joc j=Joc.getJocinstance();
					j.setState(JocStates.CANI);
					j.setInitialvalue(getDataFromTextField());
					SimulareDesenPanel.textdesen.setText("");
			}
			}
		}

		
	}


}
